package com.lzkj.baotouhousingfund.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.coderc.library.RxImageTool;
import com.lzkj.baotouhousingfund.R;
import com.lzkj.baotouhousingfund.base.ToolbarSimpleActivity;
import com.lzkj.baotouhousingfund.ui.adapter.FragmentAdapter;
import com.lzkj.baotouhousingfund.ui.fragment.GovernmentAffairsNewsFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author lx
 * @description 政务新闻
 * @date 2018-3-13 09:32:22
 */

public class GovernmentAffairsNewsActivity extends ToolbarSimpleActivity {


    @BindArray(R.array.government_affairs_news)
    String[]  mTitles;
    @BindView(R.id.toolbar_right_img)
    ImageView mToolbarRightImg;
    @BindView(R.id.tabLayout)
    TabLayout mTabLayout;
    @BindView(R.id.viewPager)
    ViewPager mViewPager;

    private List<Fragment> mFragments;
    private FragmentAdapter mFragmentPagerAdapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_government_affairs_news;
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, GovernmentAffairsNewsActivity.class);
        context.startActivity(intent);
    }

    @OnClick(R.id.toolbar_right_img)
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.toolbar_right_img:
                finish();
                break;
            default:
                break;
        }
    }
    @Override
    protected void initEventAndData() {
        mFragments = new ArrayList<>();

        GovernmentAffairsNewsFragment fragment1 = new GovernmentAffairsNewsFragment();
        GovernmentAffairsNewsFragment fragment2 = new GovernmentAffairsNewsFragment();
        GovernmentAffairsNewsFragment fragment3 = new GovernmentAffairsNewsFragment();
        GovernmentAffairsNewsFragment fragment4 = new GovernmentAffairsNewsFragment();

        fragment1.setType(1);
        fragment2.setType(2);
        fragment3.setType(3);
        fragment4.setType(4);

        mFragments.add(fragment1);
        mFragments.add(fragment2);
        mFragments.add(fragment3);
        mFragments.add(fragment4);

        mFragmentPagerAdapter=new FragmentAdapter(getSupportFragmentManager(),mFragments);
        mViewPager.setAdapter(mFragmentPagerAdapter);
        for (String mTitle : mTitles) {
            mTabLayout.addTab(mTabLayout.newTab().setText(mTitle));
        }
        mTabLayout.setupWithViewPager(mViewPager);
        for (int i = 0; i < mTitles.length; i++) {
            mTabLayout.getTabAt(i).setText(mTitles[i]);
        }
        //设置分割线
        LinearLayout linearLayout = (LinearLayout) mTabLayout.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
                R.drawable.tab_divider)); //设置分割线的样式
        linearLayout.setDividerPadding(RxImageTool.dip2px(10)); //设置分割线间隔


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mToolbarTitle.setText("政务新闻");
        mToolbarRightImg.setVisibility(View.VISIBLE);
        mToolbarRightImg.setImageResource(R.mipmap.ic_home);
    }
}
